/*
 * @Author: your name
 * @Date: 2021-01-23 19:43:12
 * @LastEditTime: 2021-01-23 20:08:21
 * @LastEditors: Please set LastEditors
 * @Description: 文件上传 处理工具  FormData接收类型中间件
 * @FilePath: \express-seed\utils\multer.js
 */
// req.files 是 `photos` 文件数组的信息
// req.body 将具有文本域数据，如果存在的话
const multer = require('multer')
const path = require('path')
const storage = multer.diskStorage({ //文件存储配置
    destination: (req, file, cb) => {
        cb(null, path.resolve(__dirname, '../public/img'))
    },
    filename: (req, file, cb) => {
        const singfileArray = file.originalname.split('.');
        cb(null, singfileArray[0] + '-' + Date.now() + '.' + Math.random() + "." + file.mimetype.replace(/^.+\//, ''));
        console.log(file);
    }
})
module.exports = multer({ storage })